package com.activitycode.util;

import android.content.Context;
import android.content.SharedPreferences;


public class SharedUtil{
	public final static String LOGIN = "Login";
	public final static String LOGINPASSREMEBER = "LOGINPASSREMEBER";
	public final static String LOGINAUTO = "LOGINAUTO";
	public final static String CITY = "CITY";
	public final static String DISTRICT = "DISTRICT";
	public final static String CITYLOG = "CITYLOG";
	public final static String HELPTAG = "HELPTAG";
	public final static String HOMETAG = "HOMETAG";
	public final static String COMPANYTAG = "COMPANYTAG";
	public final static String EMPTYTAG = "EMPTYTAG";
	public final static String XMPP_USERNAME = "XMPP_USERNAME";
	public final static String XMPP_PASSWORD = "XMPP_PASSWORD";
	
	public final static String BINDINGSTATUS = "BINDINGSTATUS";
	
	public final static String REGISTER_ALREADY = "REGISTER_ALREADY";
	
	/**
	 * keep REGISTER_ALREADY
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveRegisterAlready(Context context, Boolean isOpen) {
		SharedPreferences sp = context.getSharedPreferences(REGISTER_ALREADY, 0);
		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("open", isOpen);
		editor.commit();
	}

	public static Boolean getRegisterAlready(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(REGISTER_ALREADY, 0);
		Boolean isOpen = sp.getBoolean("open", false);
		return isOpen;
	}
	
	/**
	 * keep ad
	 * @param context
	 * @param name
	 */
	public static void saveBindingStatus(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(BINDINGSTATUS, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("status", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getBindingStatus(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(BINDINGSTATUS, 0);
		String isOpen = sp.getString("status", CommConstant.BINDING_STATUS_NONE);
		
		return isOpen;
	}
	
	/**
	 * keep ad
	 * @param context
	 * @param name
	 */
	public static void saveUserId(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(LOGIN, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("user_id", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getUserId(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGIN, 0);
		String isOpen = sp.getString("user_id", "");
		
		return isOpen;
	}
	
	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void savePassStatus(Context context, boolean isOpen) {

		SharedPreferences sp = context
				.getSharedPreferences(LOGINPASSREMEBER, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("status", isOpen);

		editor.commit();
	}

	public static boolean getPassStatus(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGINPASSREMEBER, 0);
		boolean isOpen = sp.getBoolean("status", true);

		return isOpen;
	}

	/**
	 * keep ad
	 * 
	 * @param context
	 * @param name
	 */
	public static void saveLoginAuto(Context context, boolean isOpen) {

		SharedPreferences sp = context.getSharedPreferences(LOGINAUTO, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putBoolean("status", isOpen);

		editor.commit();
	}

	public static boolean getLoginAuto(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGINAUTO, 0);
		boolean isOpen = sp.getBoolean("status", true);

		return isOpen;
	}
	
	public static void saveXmppUserId(Context context, String userId) {

		SharedPreferences sp = context.getSharedPreferences(
				XMPP_USERNAME, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("user_id", userId);
		editor.commit();
	}

	public static String getXmppUserId(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(
				XMPP_USERNAME, 0);
		String isOpen = sp.getString("user_id", "");

		return isOpen;
	}

	public static void saveXmppUserPass(Context context, String userPass) {

		SharedPreferences sp = context.getSharedPreferences(
				XMPP_PASSWORD, 0);

		SharedPreferences.Editor editor = sp.edit();
		editor.clear();
		editor.putString("user_pass", userPass);
		editor.commit();
	}

	public static String getXmppUserPass(Context context) {
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(
				XMPP_PASSWORD, 0);
		String isOpen = sp.getString("user_pass", "");

		return isOpen;
	}
	
	/**
	 * keep ad
	 * @param context
	 * @param name
	 */
	public static void saveHome(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(HOMETAG, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("home", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getHome(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HOMETAG, 0);
		String isOpen = sp.getString("home", "");
		
		return isOpen;
	}
	
	/**
	 * keep ad
	 * @param context
	 * @param name
	 */
	public static void saveCompany(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(COMPANYTAG, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("company", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getCompany(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(COMPANYTAG, 0);
		String isOpen = sp.getString("company", "");
		
		return isOpen;
	}
	
	/**
	 * keep title
	 * @param context
	 * @param name
	 */
	public static void saveCityName(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(CITY, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("city", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getCityName(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(CITY, 0);
		String isOpen = sp.getString("city", "");
		
		return isOpen;
	}
	
	/**
	 * keep title
	 * @param context
	 * @param name
	 */
	public static void saveDistrictName(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(DISTRICT, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("district", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getDistrictName(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(DISTRICT, 0);
		String isOpen = sp.getString("district", "");
		
		return isOpen;
	}
	
	/**
	 * keep last
	 * @param context
	 * @param name
	 */
	public static void saveCityStatus(Context context, Boolean isOpen)
	{	      
		  SharedPreferences sp = context.getSharedPreferences(CITYLOG, 0); 		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putBoolean("open", isOpen);
	      editor.commit();
	 }
	
	public static Boolean getCityStatus(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(CITYLOG, 0);
		Boolean isOpen = sp.getBoolean("open", true);		
		return isOpen;
	}
	
	/**
	 * keep help first
	 * @param context
	 * @param name
	 */
	public static void saveHelpStatus(Context context, Boolean isOpen,String version)
	{	      
		  SharedPreferences sp = context.getSharedPreferences(HELPTAG, 0); 		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putBoolean("open", isOpen);
	      editor.putString("version", version);
	      editor.commit();
	 }
	
	public static Boolean getHelpStatus(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HELPTAG, 0);
		Boolean isOpen = sp.getBoolean("open", true);		
		return isOpen;
	}
	
	public static String getHelpVersion(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HELPTAG, 0);
		String ver = sp.getString("version", "1.0.0");
				
		return ver;
	}
	
	/**
	 * keep last
	 * @param context
	 * @param name
	 */
	public static void saveEmptyStatus(Context context, Boolean isOpen)
	{	      
		  SharedPreferences sp = context.getSharedPreferences(EMPTYTAG, 0); 		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putBoolean("open", isOpen);
	      editor.commit();
	 }
	
	public static Boolean getEmptyStatus(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(EMPTYTAG, 0);
		Boolean isOpen = sp.getBoolean("open", true);		
		return isOpen;
	}
	
}